/*
  Copyright 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  KimNgan Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using SES.CMS.DO;
/// <summary>
/// Summary description for cmsProductDAL
/// </summary>
namespace SES.CMS.DAL
{

    public class cmsProductDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsProductDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsProductDO objcmsProductDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DetailDescription", SqlDbType.NText);
            Sqlparam.Value = objcmsProductDO.DetailDescription;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductImage", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductImage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsNew", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsNew;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsBestbuy", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsBestbuy;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Price", SqlDbType.BigInt);
            Sqlparam.Value = objcmsProductDO.Price;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ChartImage", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ChartImage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsPromotion", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsPromotion;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SalePrice", SqlDbType.BigInt);
            Sqlparam.Value = objcmsProductDO.SalePrice;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsSetTop", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsSetTop;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsHomepage", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsHomepage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsFinished", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsFinished;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PromotionEndDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsProductDO.PromotionEndDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OriginID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.OriginID;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@Active", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.Active;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BrandID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.BrandID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thumbnail", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.Thumbnail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PromotionImages", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.PromotionImages;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Warranty", SqlDbType.NText);
            Sqlparam.Value = objcmsProductDO.Warranty;
            Sqlcomm.Parameters.Add(Sqlparam);
            
            
            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }
        public int UpdateOrInsertByProductCode(cmsProductDO objcmsProductDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_InsertOrUpdate_ByProductCode";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductCategoryCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DetailDescription", SqlDbType.NText);
            Sqlparam.Value = objcmsProductDO.DetailDescription;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductImage", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductImage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsNew", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsNew;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsBestbuy", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsBestbuy;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Price", SqlDbType.BigInt);
            Sqlparam.Value = objcmsProductDO.Price;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thumbnail", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.Thumbnail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OriginID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.OriginID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BrandID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.BrandID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PromotionImages", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.PromotionImages;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Warranty", SqlDbType.NText);
            Sqlparam.Value = objcmsProductDO.Warranty;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;
        }

        public int Update(cmsProductDO objcmsProductDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.ProductID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCode", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductCode;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductTitle", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductTitle;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.ProductCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Description", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.Description;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@DetailDescription", SqlDbType.NText);
            Sqlparam.Value = objcmsProductDO.DetailDescription;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ProductImage", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ProductImage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsNew", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsNew;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Thumbnail", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.Thumbnail;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsBestbuy", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsBestbuy;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.OrderID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Price", SqlDbType.BigInt);
            Sqlparam.Value = objcmsProductDO.Price;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ChartImage", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.ChartImage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsPromotion", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsPromotion;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SalePrice", SqlDbType.BigInt);
            Sqlparam.Value = objcmsProductDO.SalePrice;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsSetTop", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsSetTop;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsHomepage", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsHomepage;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsFinished", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.IsFinished;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PromotionEndDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsProductDO.PromotionEndDate;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@OriginID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.OriginID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@BrandID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.BrandID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Active", SqlDbType.Bit);
            Sqlparam.Value = objcmsProductDO.Active;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@PromotionImages", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsProductDO.PromotionImages;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Warranty", SqlDbType.NText);
            Sqlparam.Value = objcmsProductDO.Warranty;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsProductDO objcmsProductDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.ProductID;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsProductDO Select(cmsProductDO objcmsProductDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = objcmsProductDO.ProductID;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["ProductID"]))
                    objcmsProductDO.ProductID = Convert.ToInt32(dr["ProductID"]);
                if (!Convert.IsDBNull(dr["ProductCode"]))
                    objcmsProductDO.ProductCode = Convert.ToString(dr["ProductCode"]);
                if (!Convert.IsDBNull(dr["ProductTitle"]))
                    objcmsProductDO.ProductTitle = Convert.ToString(dr["ProductTitle"]);
                if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                    objcmsProductDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                if (!Convert.IsDBNull(dr["Description"]))
                    objcmsProductDO.Description = Convert.ToString(dr["Description"]);
                if (!Convert.IsDBNull(dr["DetailDescription"]))
                    objcmsProductDO.DetailDescription = Convert.ToString(dr["DetailDescription"]);
                if (!Convert.IsDBNull(dr["ProductImage"]))
                    objcmsProductDO.ProductImage = Convert.ToString(dr["ProductImage"]);
                if (!Convert.IsDBNull(dr["IsNew"]))
                    objcmsProductDO.IsNew = Convert.ToBoolean(dr["IsNew"]);
                if (!Convert.IsDBNull(dr["IsBestbuy"]))
                    objcmsProductDO.IsBestbuy = Convert.ToBoolean(dr["IsBestbuy"]);
                if (!Convert.IsDBNull(dr["OrderID"]))
                    objcmsProductDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                if (!Convert.IsDBNull(dr["Price"]))
                    objcmsProductDO.Price = Convert.ToInt64(dr["Price"]);
                if (!Convert.IsDBNull(dr["ChartImage"]))
                    objcmsProductDO.ChartImage = Convert.ToString(dr["ChartImage"]);
                if (!Convert.IsDBNull(dr["IsPromotion"]))
                    objcmsProductDO.IsPromotion = Convert.ToBoolean(dr["IsPromotion"]);
                if (!Convert.IsDBNull(dr["SalePrice"]))
                    objcmsProductDO.SalePrice = Convert.ToInt64(dr["SalePrice"]);
                if (!Convert.IsDBNull(dr["IsSetTop"]))
                    objcmsProductDO.IsSetTop = Convert.ToBoolean(dr["IsSetTop"]);
                if (!Convert.IsDBNull(dr["IsHomepage"]))
                    objcmsProductDO.IsHomepage = Convert.ToBoolean(dr["IsHomepage"]);
                if (!Convert.IsDBNull(dr["IsFinished"]))
                    objcmsProductDO.IsFinished = Convert.ToBoolean(dr["IsFinished"]);
                if (!Convert.IsDBNull(dr["PromotionEndDate"]))
                    objcmsProductDO.PromotionEndDate = Convert.ToDateTime(dr["PromotionEndDate"]);
                if (!Convert.IsDBNull(dr["OriginID"]))
                    objcmsProductDO.OriginID = Convert.ToInt32(dr["OriginID"]);
                if (!Convert.IsDBNull(dr["BrandID"]))
                    objcmsProductDO.BrandID = Convert.ToInt32(dr["BrandID"]);
                if (!Convert.IsDBNull(dr["Active"]))
                    objcmsProductDO.Active = Convert.ToBoolean(dr["Active"]);
                if (!Convert.IsDBNull(dr["Thumbnail"]))
                    objcmsProductDO.Thumbnail = Convert.ToString(dr["Thumbnail"]);
                if (!Convert.IsDBNull(dr["PromotionImages"]))
                    objcmsProductDO.PromotionImages = Convert.ToString(dr["PromotionImages"]);
                if (!Convert.IsDBNull(dr["Warranty"]))
                    objcmsProductDO.Warranty = Convert.ToString(dr["Warranty"]);

            }
            return objcmsProductDO;
        }

        public DataTable SelectByPK(int productID)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = productID;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsProductDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsProductDO objcmsProductDO = new cmsProductDO();
                    if (!Convert.IsDBNull(dr["ProductID"]))
                        objcmsProductDO.ProductID = Convert.ToInt32(dr["ProductID"]);
                    if (!Convert.IsDBNull(dr["ProductCode"]))
                        objcmsProductDO.ProductCode = Convert.ToString(dr["ProductCode"]);
                    if (!Convert.IsDBNull(dr["ProductTitle"]))
                        objcmsProductDO.ProductTitle = Convert.ToString(dr["ProductTitle"]);
                    if (!Convert.IsDBNull(dr["ProductCategoryID"]))
                        objcmsProductDO.ProductCategoryID = Convert.ToInt32(dr["ProductCategoryID"]);
                    if (!Convert.IsDBNull(dr["Description"]))
                        objcmsProductDO.Description = Convert.ToString(dr["Description"]);
                    if (!Convert.IsDBNull(dr["DetailDescription"]))
                        objcmsProductDO.DetailDescription = Convert.ToString(dr["DetailDescription"]);
                    if (!Convert.IsDBNull(dr["ProductImage"]))
                        objcmsProductDO.ProductImage = Convert.ToString(dr["ProductImage"]);
                    if (!Convert.IsDBNull(dr["IsNew"]))
                        objcmsProductDO.IsNew = Convert.ToBoolean(dr["IsNew"]);
                    if (!Convert.IsDBNull(dr["IsBestbuy"]))
                        objcmsProductDO.IsBestbuy = Convert.ToBoolean(dr["IsBestbuy"]);
                    if (!Convert.IsDBNull(dr["OrderID"]))
                        objcmsProductDO.OrderID = Convert.ToInt32(dr["OrderID"]);
                    if (!Convert.IsDBNull(dr["Price"]))
                        objcmsProductDO.Price = Convert.ToInt64(dr["Price"]);
                    if (!Convert.IsDBNull(dr["ChartImage"]))
                        objcmsProductDO.ChartImage = Convert.ToString(dr["ChartImage"]);
                    if (!Convert.IsDBNull(dr["IsPromotion"]))
                        objcmsProductDO.IsPromotion = Convert.ToBoolean(dr["IsPromotion"]);
                    if (!Convert.IsDBNull(dr["SalePrice"]))
                        objcmsProductDO.SalePrice = Convert.ToInt64(dr["SalePrice"]);
                    if (!Convert.IsDBNull(dr["IsSetTop"]))
                        objcmsProductDO.IsSetTop = Convert.ToBoolean(dr["IsSetTop"]);
                    if (!Convert.IsDBNull(dr["IsHomepage"]))
                        objcmsProductDO.IsHomepage = Convert.ToBoolean(dr["IsHomepage"]);
                    if (!Convert.IsDBNull(dr["IsFinished"]))
                        objcmsProductDO.IsFinished = Convert.ToBoolean(dr["IsFinished"]);
                    if (!Convert.IsDBNull(dr["PromotionEndDate"]))
                        objcmsProductDO.PromotionEndDate = Convert.ToDateTime(dr["PromotionEndDate"]);
                    if (!Convert.IsDBNull(dr["OriginID"]))
                        objcmsProductDO.OriginID = Convert.ToInt32(dr["OriginID"]);
                    if (!Convert.IsDBNull(dr["BrandID"]))
                        objcmsProductDO.BrandID = Convert.ToInt32(dr["BrandID"]);
                    if (!Convert.IsDBNull(dr["Thumbnail"]))
                        objcmsProductDO.Thumbnail = Convert.ToString(dr["Thumbnail"]);
                    if (!Convert.IsDBNull(dr["PromotionImages"]))
                        objcmsProductDO.PromotionImages = Convert.ToString(dr["PromotionImages"]);
                    if (!Convert.IsDBNull(dr["Warranty"]))
                        objcmsProductDO.Warranty = Convert.ToString(dr["Warranty"]);

                    arrcmsProductDO.Add(objcmsProductDO);
                }
            }
            return arrcmsProductDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByProductCategory(int productCategoryID)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByFK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = productCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByProductCategoryTop(int productCategoryID, int ProductID)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByTop";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = productCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);
            Sqlparam = new SqlParameter("@ProductID", SqlDbType.Int);
            Sqlparam.Value = ProductID;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByProductCategoryAndKeyword(int productCategoryID, string keyword)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_Search";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@CategoryID", SqlDbType.Int);
            Sqlparam.Value = productCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Keyword", SqlDbType.NVarChar);
            Sqlparam.Value = keyword;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByProductCategoryAll(int productCategoryID)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByCate";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = productCategoryID;
            Sqlcomm.Parameters.Add(Sqlparam);
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        #endregion
        public DataTable SelectFrontPage(int top, int isNew, int isBestBuy, int isPromotion, int isSetTop)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_FrontPage";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Top", SqlDbType.Int);
            Sqlparam.Value = top;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsNew", SqlDbType.Int);
            Sqlparam.Value = isNew;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsBestBuy", SqlDbType.Int);
            Sqlparam.Value = isBestBuy;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsPromotion", SqlDbType.Int);
            Sqlparam.Value = isPromotion;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsSetTop", SqlDbType.Int);
            Sqlparam.Value = isSetTop;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SimpleSearch(string keyword)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_SimpleSearch";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Keyword", SqlDbType.NVarChar);
            Sqlparam.Value = keyword;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetByPrice(object fromPrice, object toPrice)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_SearchByPrice";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@FromPrice", SqlDbType.Money);
            Sqlparam.Value = fromPrice;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToPrice", SqlDbType.Money);
            Sqlparam.Value = toPrice;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable MobileHomepageProduct(int top)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetMobileHomepageProduct";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Top", SqlDbType.Int);
            Sqlparam.Value = top;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable GetByOriginID(int OriginId)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByOriginID";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@OriginID", SqlDbType.Int);
            Sqlparam.Value = OriginId;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetByIsNew(bool IsNew)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByIsNew";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@IsNew", SqlDbType.Bit);
            Sqlparam.Value = IsNew;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable GetByIsPromotion(bool IsPromotion)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_GetByPromotions";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@IsPromotion", SqlDbType.Bit);
            Sqlparam.Value = IsPromotion;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }

        public DataTable SearchSenior(int productCateId, int OriginId, object fromPrice, object toPrice, int isPrice)
        {
            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsProduct_SearchSenior";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@ProductCategoryID", SqlDbType.Int);
            Sqlparam.Value = productCateId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OriginID", SqlDbType.Int);
            Sqlparam.Value = OriginId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@FromPrice", SqlDbType.Int);
            Sqlparam.Value = fromPrice;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ToPrice", SqlDbType.Int);
            Sqlparam.Value = toPrice;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@IsPrice", SqlDbType.Int);
            Sqlparam.Value = isPrice;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
    }

}
